/**
    The Player class extends the Sprite class to add states
    (STATE_NORMAL or STATE_JUMPING) and gravity.
*/
public class Player extends Sprite {

    public static final int STATE_NORMAL = 0;
    public static final int STATE_JUMPING = 1;

    public static final float SPEED = .3f;		//Default Speed = .3f = dx
    public static final float GRAVITY = .002f; // Default Gravity = .002f = dy

    private int state;
    
    public Player(Animation anim) {
        super(anim);
        state = STATE_NORMAL;
    }


    /**
        Gets the state of the Player (either STATE_NORMAL or
        STATE_JUMPING);
    */
    public int getState() {
        return state;
    }


    /**
        Sets the state of the Player (either STATE_NORMAL or
        STATE_JUMPING);
    */
    public void setState(int state) {
        this.state = state;
    }

    /**
        Causes the Player to jump
    */
    public void jump() {
    	DMastaGX.MasterGX.CanDropDown = false;
    	DMastaGX.MasterGX.setFloorY(1500); // Set the Floor Below the Map
        setVelocityY(-1f);
        state = STATE_JUMPING;
    }
    
    /**
    Causes the Player to drop to the Floor
    */
    public void dropToFloor() {
    		
    DMastaGX.MasterGX.CanDropDown = true;
    DMastaGX.MasterGX.FallingToFLoor = true;
    DMastaGX.MasterGX.setFloorY(1500); // Set the Floor Below the Map
    if(DMastaGX.MasterGX.LookingLeft == false)
    DMastaGX.MasterGX.changeAnimation(DMastaGX.MasterGX.FallingRIGHT);
    else DMastaGX.MasterGX.changeAnimation(DMastaGX.MasterGX.FallingLEFT);
    setVelocityY(.002f); // Default = .002f // Drop Velocity
    state = STATE_JUMPING; // Say that he's Jumping in order for the Update to Check for a Floor
   
}


    /**
        Updates the player's position and animation. Also, sets the
        Player's state to NORMAL if a jumping Player landed on
        the floor.
    */
    public void UpdatePlayer(long elapsedTime) {
    	
        // set vertical velocity (gravity effect)
        if (getState() == STATE_JUMPING) {
            setVelocityY(getVelocityY() + GRAVITY * elapsedTime);
        }

        // move player
        super.UpdateSprite(elapsedTime);

        // check if player landed on floor. If True put The PLayer on the Floor
        if (getState() == STATE_JUMPING && getY() >= DMastaGX.MasterGX.getFloor()) {
            setVelocityY(0);
            setY(DMastaGX.MasterGX.getFloor());
            setState(STATE_NORMAL);
            
            //    My Special Variables 
            // Player is in the floor and Can now Crouch
            if(state == 0)DMastaGX.MasterGX.CanCrouch = true;
            // The PLayer is in the floor and Finished Dash Jumping
            if(state == 0)DMastaGX.MasterGX.IsDashJumping = false; 
     //        Action to be taken by the user after landing The User decided to Stand.
             if(DMastaGX.LandThenStand == true) 
            	 if(DMastaGX.MasterGX.LookingLeft == false) 
            	 changeAnimation(DMastaGX.MasterGX.StandingRIGHT);
            	 else changeAnimation(DMastaGX.MasterGX.StandingLEFT);
             // The user decided to run and his velocity is changed to the Running Velocity and Animation
             if(DMastaGX.MasterGX.LandThenStand == false){
            	 if(DMastaGX.MasterGX.LookingLeft == false)
          	   changeAnimation(DMastaGX.MasterGX.RunningRIGHT);
            	 else changeAnimation(DMastaGX.MasterGX.RunningLEFT);
             }
            // If you're on the floor and Dash is Released Change to standing Animation 
             else  if(state == 0 && MasterControl.A_Pressed == false){
            	 if(DMastaGX.MasterGX.LookingLeft == false)
           	  DMastaGX.MasterGX.changeAnimation(DMastaGX.MasterGX.StandingRIGHT);
            	 else DMastaGX.MasterGX.changeAnimation(DMastaGX.MasterGX.StandingLEFT);
           	  DMastaGX.MasterGX.setVelocityX(0); 
             }

        }
        
        

    }
    
}

